package com.ttx.pattern.example.iterator.after;

/**
 * @author TimFruit
 * @date 19-6-12 下午10:40
 */
public class Client {

    public static void main(String[] args) {
        ConcreteAggregate aggregate=new ConcreteAggregate();

        aggregate.add("t0");
        aggregate.add("t1");
        aggregate.add("t2");
        aggregate.add("t3");
        aggregate.add("t4");

        System.out.println(aggregate);  //[t0, t1, t2, t3, t4]


        aggregate.remove(3);
        System.out.println(aggregate);  // [t0, t1, t2, t4]

        aggregate.add("t5");
        System.out.println(aggregate);  // [t0, t1, t2, t4, t5]


        aggregate.remove("t2");
        System.out.println(aggregate);  // [t0, t1, t4, t5]


        System.out.println("------iterator------"); // t0 , t4 , t5 ,
        Iterator<String> iterator=aggregate.iterator();
        while (iterator.hasNext()){
            String e=iterator.next();
            if(e.equals("t1")){
                iterator.remove();
            }else {
                System.out.print(e +" , ");
            }

        }

    }

}
